function isEmpty(str){
  if(!str && typeof(str)!="undefined" && str!==0){
    return true;
  }else{
    return false;
  }
}
$.fn.selectReadOnly=function(){
    var tem=$(this).children('option').index($("option:selected"));
    $(this).css("style","background-color: gray");
    $(this).change(function(){
          $(this).children('option').eq(tem).attr("selected",true);
    });
};

$.fn.unReadOnly=function(){
    $(this).css("style","");
    $(this).unbind("change");
};

Date.prototype.format = function(format){
      var o = {
         "M+" :  this.getMonth()+1,  //month
         "d+" :  this.getDate(),     //day
         "h+" :  this.getHours(),    //hour
         "m+" :  this.getMinutes(),  //minute
         "s+" :  this.getSeconds(), //second
         "q+" :  Math.floor((this.getMonth()+3)/3),  //quarter
         "S"  :  this.getMilliseconds() //millisecond
       };
  
   if(/(Y+)/.test(format)) {
      format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
   }
 
   for(var k in o) {
    if(new RegExp("("+ k +")").test(format)) {
      format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
    }
   }
   return format;
};

Date.prototype.compareDate = function (compareDate, endDate){
  var day;
  if(isEmpty(endDate)){
     day = new Date();
  }else{
     day = endDate;
  }
  var Year=0;
  var Month=0;
  var Day=0;
  var Hour = 0;
  var Minute = 0;
  var Second = 0;
  
  //初始化时间
  Year       = day.getYear();
  Month      = (day.getMonth()+1);
  Day        = day.getDate();
  Hour       = day.getHours();
  Minute     = day.getMinutes();
  Second     = day.getSeconds();
  
  //----------------------------------------------
  //var bt = "2011-07-03 12:13:14";
  var theYear       = compareDate.getYear();
  var theMonth      = (compareDate.getMonth()+1);
  var theDay        = compareDate.getDate();
  var theHour       = compareDate.getHours();
  var theMinute     = compareDate.getMinutes();
  var theSecond     = compareDate.getSeconds();
  
  var a= new Date(theYear,theMonth,theDay);  //选择的时间
  var b= new Date(Year,Month,Day); //现在的时间
  return parseInt(Math.floor(a - b)/(1000*60*60*24)); //返回天数
};

var PaginatedTools = {callbackFun:"", nowPage:1, setCallBackFun:function (callbackFun) {
	var self = this;
	self.callbackFun = callbackFun;
}, prePage:function (nowPage) {
	var self = this;
	self.nowPage = parseInt(nowPage);
	if (nowPage <= 0) {
		self.nowPage = 1;
	} else {
		if (nowPage == 1) {
			self.nowPage = 1;
		} else {
			self.nowPage = parseInt(nowPage) - 1;
		}
	}
	self.jumpToPage();
}, nextPage:function (nowPage, pageCnt) {
	var self = this;
	self.nowPage = parseInt(nowPage);
	if (nowPage <= 0) {
		self.nowPage = 1;
	} else {
		if (nowPage >= pageCnt) {
			self.nowPage = pageCnt;
		} else {
			self.nowPage = parseInt(nowPage) + 1;
		}
	}
	self.jumpToPage();
}, jumpPage:function (jumpPage, nowPage, pageCnt) {
	var self = this;
	if (jumpPage <= 0) {
		jumpPage = 1;
	} else {
		if (jumpPage > pageCnt) {
			jumpPage = pageCnt;
		}
	}
	self.nowPage = (jumpPage);
	self.jumpToPage();
}, jumpWithIdElem:function (id, nowPage, pageCnt) {
	var self = this;
	self.jumpPage(document.getElementById(id).value,nowPage,pageCnt);
}, lastPage:function (nowPage, pageCnt) {
	var self = this;
	self.nowPage = (pageCnt);
	self.jumpToPage();
}, firstPage:function (nowPage, pageCnt) {
	var self = this;
	self.nowPage = 1;
	self.jumpToPage();
}, jumpToPage:function () {
	var self = this;
	this.callbackFun(self.nowPage);
}};